<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-ability__bsabilityai">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.name" placeholder="名称" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.shareForm" placeholder="共享形式">
           <el-option v-for="shareFormItem in shareFormArr" :key="shareFormItem.data" :label="shareFormItem.label" :value="shareFormItem.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.field" placeholder="领域">
             <el-option v-for="fieldItem in fieldArr" :key="fieldItem.data" :label="fieldItem.label" :value="fieldItem.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.scene" placeholder="场景">
           <el-option v-for="sceneItem in sceneArr" :key="sceneItem.data" :label="sceneItem.label" :value="sceneItem.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.deptId" placeholder="部门ID" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('ability:bsabilityai:save')" type="primary" @click="addOrUpdateHandle()">挂接</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('ability:bsabilityai:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="name" label="名称" header-align="center" align="center"></el-table-column>
        <el-table-column prop="version" label="版本号" header-align="center" align="center"></el-table-column>
        <el-table-column prop="subtext" label="简单介绍" header-align="center" align="center" width="320"></el-table-column>
        <!-- <el-table-column prop="imgurl" label="图片" header-align="center" align="center"></el-table-column> -->
        <el-table-column prop="imgurl" label="图标" header-align="center" align="center">
          <template slot-scope="scope">
            <svg class="icon-svg" aria-hidden="true"><use :xlink:href="`#${scope.row.imgurl}`"></use></svg>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="shareType" label="共享方式" header-align="center" align="center"></el-table-column> -->
        <el-table-column prop="goal" label="评价计分" header-align="center" align="center"></el-table-column>
        <el-table-column prop="shareForm" label="共享形式" header-align="center" align="center"></el-table-column>
        <!-- <el-table-column prop="field" label="领域 " header-align="center" align="center"></el-table-column>
        <el-table-column prop="scene" label="场景" header-align="center" align="center"></el-table-column> -->
        <el-table-column prop="deptId" label="部门" header-align="center" align="center"></el-table-column>
        <el-table-column prop="updateDate" label="上线时间" header-align="center" align="center" width="180"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('ability:bsabilityai:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('ability:bsabilityai:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
            <el-button type="text" size="small" @click="showDetail(scope.row.id)">展示</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update :disabled="disabled" v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './bsabilityai-add-or-update'
import dictionaries from '@/utils/dictionaries'

export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/ability/bsabilityai/page',
        getDataListIsPage: true,
        exportURL: '/ability/bsabilityai/export',
        deleteURL: '/ability/bsabilityai',
        deleteIsBatch: true
      },
      disabled: false,
      sceneArr: dictionaries.sceneArr,
      fieldArr: dictionaries.fieldArr,
      shareFormArr: dictionaries.shareFormArr,
      dataForm: {
        name: '',
        shareForm: '',
        field: '',
        scene: '',
        deptId: ''
      }
    }
  },
  watch: {
  },
  components: {
    AddOrUpdate
  },
  methods: {
    showDetail (id) {
      this.addOrUpdateHandle(id)
      this.disabled = true
    }
  }
}
</script>
